import axios from 'axios'
import { CHANNEL_ACTIVE, CHANNEL_LIST } from '../constants'

// 获取频道列表
export const getChannelListAc = (payload) => ({
  type: CHANNEL_LIST,
  payload,
})

export const getChannelList = () => {
  return async (dispatch) => {
    const {
      data: {
        data: { channels },
      },
    } = await axios.get('http://geek.itheima.net/v1_0/channels')
    // 再次 dispatch 会触发 reducer 的执行
    dispatch(getChannelListAc(channels))
  }
}

export const changeActive = (id) => ({
  type: CHANNEL_ACTIVE,
  id,
})
